package orders

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/orders"
    ordersReq "github.com/flipped-aurora/gin-vue-admin/server/model/orders/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "github.com/flipped-aurora/gin-vue-admin/server/utils"
)

type LsOrderApi struct {}



// CreateLsOrder 创建lsOrder表
// @Tags LsOrder
// @Summary 创建lsOrder表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body orders.LsOrder true "创建lsOrder表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /lsOrder/createLsOrder [post]
func (lsOrderApi *LsOrderApi) CreateLsOrder(c *gin.Context) {
	var lsOrder orders.LsOrder
	err := c.ShouldBindJSON(&lsOrder)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    lsOrder.CreatedBy = utils.GetUserID(c)
	err = lsOrderService.CreateLsOrder(&lsOrder)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteLsOrder 删除lsOrder表
// @Tags LsOrder
// @Summary 删除lsOrder表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body orders.LsOrder true "删除lsOrder表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /lsOrder/deleteLsOrder [delete]
func (lsOrderApi *LsOrderApi) DeleteLsOrder(c *gin.Context) {
	ID := c.Query("ID")
    userID := utils.GetUserID(c)
	err := lsOrderService.DeleteLsOrder(ID,userID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteLsOrderByIds 批量删除lsOrder表
// @Tags LsOrder
// @Summary 批量删除lsOrder表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /lsOrder/deleteLsOrderByIds [delete]
func (lsOrderApi *LsOrderApi) DeleteLsOrderByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
    userID := utils.GetUserID(c)
	err := lsOrderService.DeleteLsOrderByIds(IDs,userID)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateLsOrder 更新lsOrder表
// @Tags LsOrder
// @Summary 更新lsOrder表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body orders.LsOrder true "更新lsOrder表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /lsOrder/updateLsOrder [put]
func (lsOrderApi *LsOrderApi) UpdateLsOrder(c *gin.Context) {
	var lsOrder orders.LsOrder
	err := c.ShouldBindJSON(&lsOrder)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    lsOrder.UpdatedBy = utils.GetUserID(c)
	err = lsOrderService.UpdateLsOrder(lsOrder)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindLsOrder 用id查询lsOrder表
// @Tags LsOrder
// @Summary 用id查询lsOrder表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param ID query uint true "用id查询lsOrder表"
// @Success 200 {object} response.Response{data=orders.LsOrder,msg=string} "查询成功"
// @Router /lsOrder/findLsOrder [get]
func (lsOrderApi *LsOrderApi) FindLsOrder(c *gin.Context) {
	ID := c.Query("ID")
	relsOrder, err := lsOrderService.GetLsOrder(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(relsOrder, c)
}
// GetLsOrderList 分页获取lsOrder表列表
// @Tags LsOrder
// @Summary 分页获取lsOrder表列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query ordersReq.LsOrderSearch true "分页获取lsOrder表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /lsOrder/getLsOrderList [get]
func (lsOrderApi *LsOrderApi) GetLsOrderList(c *gin.Context) {
	var pageInfo ordersReq.LsOrderSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := lsOrderService.GetLsOrderInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetLsOrderPublic 不需要鉴权的lsOrder表接口
// @Tags LsOrder
// @Summary 不需要鉴权的lsOrder表接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /lsOrder/getLsOrderPublic [get]
func (lsOrderApi *LsOrderApi) GetLsOrderPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    lsOrderService.GetLsOrderPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的lsOrder表接口信息",
    }, "获取成功", c)
}
